home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n21.arc / DGPARAM.PAS < prev    next >
Pascal/Delphi Source File  |  1990-11-17  |  6KB  |  159 lines

  1. {
  2.  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3.  █                                                                         █
  4.  █        TITLE :      DGPARAM.TPU                                         █
  5.  █      PURPOSE :      Parameter and Command Line handling.                █
  6.  █       AUTHOR :      David Gerrold, CompuServe ID:  70307,544            █
  7.  █ ______________________________________________________________________  █
  8.  █                                                                         █
  9.  █   Written in Turbo Pascal, Version 5.5,                                 █
  10.  █   with routines from TurboPower, Object Professional.                   █
  11.  █                                                                         █
  12.  █   Turbo Pascal is a product of Borland International.                   █
  13.  █   Object Professional is a product of TurboPower Software.              █
  14.  █ ______________________________________________________________________  █
  15.  █                                                                         █
  16.  █   This is not public domain software.                                   █
  17.  █   This software is copyright 1990, by David Gerrold.                    █
  18.  █   Permission is hereby granted for personal use.                        █
  19.  █                                                                         █
  20.  █        The Brass Cannon Corporation                                     █
  21.  █        9420 Reseda Blvd., #804                                          █
  22.  █        Northridge, CA  91324-2932.                                      █
  23.  █                                                                         █
  24.  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  25.                                                                             }
  26. { Compiler Directives ===================================================== }
  27.  
  28. {$A-}    {Switch word alignment off, necessary for cloning}
  29. {$R-}    {Range checking off}
  30. {$B-}    {Boolean complete evaluation off}
  31. {$S-}    {Stack checking off}
  32. {$I-}    {I/O checking off}
  33. {$N+,E+} {Simulate numeric coprocessor}
  34. {$M 16384,0,327680} {stack and heap}
  35. {$V-}    {Variable range checking off}
  36.  
  37. { Name ==================================================================== }
  38.  
  39. UNIT DgParam;
  40. {
  41.   The purpose of DgParam is to provide routines for parsing and handling
  42.   command line parameters and parameter strings passed to a program.
  43. }
  44.  
  45. { Interface =============================================================== }
  46.  
  47. INTERFACE
  48.  
  49. USES
  50. { Object Professional Units }
  51.   OpCrt,
  52.   OpString,
  53.  
  54. { Dg Units }
  55.   DgStr;
  56.  
  57. { Declarations ============================================================ }
  58. { Constants --------------------------------------------------------------- }
  59.  
  60. CONST
  61.   ParamString    : string = '';                  { for stashing parameters }
  62.  
  63. { Functions and Procedures ================================================ }
  64.  
  65. FUNCTION GetSwitchPos (Ch : char;  S : string12) : byte;
  66. { returns pos of command line switch char in ParamString }
  67.  
  68. FUNCTION GetCommandLineSwitch (S : string12;  VAR Loop : byte) : boolean;
  69. {
  70.   reads ParamString, looks for switch S;
  71.   returns succeeding string if found, returns '' if not found.
  72. }
  73.  
  74. { ========================================================================= }
  75. { IMPLEMENTATION ========================================================== }
  76.  
  77. IMPLEMENTATION
  78.  
  79. { ========================================================================= }
  80. { GetSwitchPos ============================================================ }
  81.  
  82. FUNCTION GetSwitchPos (Ch : char;  S : string12) : byte;
  83. { returns pos of command line switch char in ParamString }
  84.  
  85. VAR
  86.   ParamUpStr : string;
  87.  
  88. BEGIN
  89.   S := StUpCase (S);
  90.   ParamUpStr := StUpCase (ParamString);
  91.   GetSwitchPos := pos (Ch + S, ParamUpStr);
  92. END;
  93.  
  94. { GetCommandLineSwitch ==================================================== }
  95.  
  96. FUNCTION GetCommandLineSwitch (S : string12;  VAR Loop : byte) : boolean;
  97. {
  98.   reads ParamString, looks for switch S;
  99.   returns succeeding string if found, returns '' if not found.
  100. }
  101.  
  102. BEGIN
  103.   GetCommandLineSwitch := false;
  104.   Loop := GetSwitchPos ('-', S);
  105.   if Loop = 0 then
  106.     Loop := GetSwitchPos ('/', S);
  107.   if Loop > 0 then
  108.     GetCommandLineSwitch := true;
  109. END;
  110.  
  111. { ========================================================================= }
  112. { Initialization ========================================================== }
  113.  
  114. VAR
  115.   Loop : byte;
  116.  
  117. BEGIN
  118.   { stuff ParamString }
  119.   For Loop := 1 to ParamCount do
  120.     ParamString := ParamString + trim (ParamStr (Loop)) + ' ';
  121.   ParamString := SpaceFix (ParamString);
  122.  
  123. {
  124.   There is no way that a program can tell if a user has a color card
  125.   connected to a bw monitor.  To force a bw display, let the user
  126.   call the program with the command line option of '-bw' or '/bw'.
  127.   The program will look through the ParamStrs and set DefColorChoice
  128.   to ForceMono.
  129.  
  130.   For this to work, however, EVERY color choice called must be mapped
  131.   with OpCrt's ColorMono (color, mono) function.
  132. }
  133.   { look for mono switch }
  134.   If GetCommandLineSwitch ('BW', Loop) then begin
  135.     DefColorChoice := ForceMono;
  136.     TextAttr := MapColor (TextAttr);
  137.     delete (ParamString, Loop, 3);
  138.     end;
  139. END.
  140.  
  141. { ========================================================================= }
  142. { DgParam History ========================================================= }
  143.  
  144. VERSION HISTORY:
  145.   9005.05
  146.     Totally restructured for consistency with Object Professional.
  147.  
  148. { DgParam Needs =========================================================== }
  149.  
  150. NEED TO ADD:
  151.   Nothing right now.
  152.  
  153. { Bug Reports ============================================================= }
  154.  
  155. BUGS:
  156.   No known bugs.
  157.  
  158. { ========================================================================= }
  159.